package com.javacv.plus.extensions.image.steps;

import com.javacv.plus.core.processor.ProcessorContext;
import com.javacv.plus.core.processor.ProcessorStep;
import com.javacv.plus.extensions.image.ImageProcessor;
import com.javacv.plus.extensions.image.ProcessorResult;
import lombok.extern.slf4j.Slf4j;
import org.bytedeco.opencv.opencv_core.Mat;

/**
 * 对比度调整步骤
 */
@Slf4j
public class ContrastStep implements ProcessorStep<ImageProcessor, ProcessorResult> {
    private final double factor;

    public ContrastStep(double factor) {
        this.factor = factor;
    }

    @Override
    public ProcessorResult execute(ImageProcessor processor, ProcessorContext context) throws Exception {
        Mat currentImage = context.getAttribute("currentImage");
        if (currentImage == null) {
            throw new IllegalStateException("当前图像为空");
        }

        log.debug("调整对比度，因子: {}", factor);

        Mat result = new Mat();
        currentImage.convertTo(result, -1, factor, 0); // 对比度调整

        context.setAttribute("currentImage", result);
        context.setAttribute("processedImage", result);

        log.debug("对比度调整完成");
        return null;
    }

    @Override
    public String getStepName() {
        return "Contrast";
    }

    @Override
    public int getPriority() {
        return 61;
    }
} 